const express = require('express')
const router = express.Router()
const db = require('../database/index')
// 获取
router.get('/cates', (req, res) => {
    res.send('获取文章分类列表成功！')
})
// 添加
router.post('/addcates', (req, res) => {
    let { name, alias } = req.body
    let sql=`insert into category set name="${name}",alias="${alias}" `
    db(sql, (err, results) => {
        if (err) {
            throw err
        }
        if (results.affectedRows !== 1) {
            return res.send('添加失败！')
        }
        res.send({
            status: 0,
            message: '添加文章分类成功',
        })
    })

})
// 删除
router.get('/deletecate/:id', (req, res) => {
    let sql = `delete from category where id=${req.params.id}`
    db(sql, (err, results) => {
        if (err) {
            throw err
        }
        if (results.affectedRows !== 1) {
            return res.send('删除失败！')
        }
        res.send({
            status: 0,
            message: '删除文章分类成功',
        })
    })

})
















module.exports = router